﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region
using System;
using ScrumTable.Common.Logging;
using ScrumTable.Common.Properties;
#endregion 
namespace ScrumTable.Common
{

    /// <summary>
    /// Defines a method to release allocated resources with defined action.
    /// </summary>
    public class DisposeAction : DisposeBase
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private readonly Action _toExecuteOnDispose;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DisposeAction instance.
        /// </summary>
        public DisposeAction(Action toExecuteOnDispose)
        {
            PreCondition.AssertNotNull(toExecuteOnDispose, "toExecuteOnDispose");
            
            _toExecuteOnDispose = toExecuteOnDispose;
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Releases managed (c# or .net) resources.
        /// </summary>
        protected override void ReleaseManagedResources()
        {
            _toExecuteOnDispose();
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}